package com.liy.framework.common.utils;

import com.fasterxml.jackson.databind.*;
import java.io.*;
import com.fasterxml.jackson.core.type.*;
import java.util.*;
import com.fasterxml.jackson.core.*;

public class JSONUtils2
{
    private static final ObjectMapper mapper;
    
    private JSONUtils2() {
    }
    
    public static Map<String, Object> json2Map(final String json) throws IOException {
        final Map map = (Map)JSONUtils2.mapper.readValue(json, (Class)Map.class);
        return (Map<String, Object>)map;
    }
    
    public static String object2Json(final Object object) throws IOException {
        return JSONUtils2.mapper.writeValueAsString(object);
    }
    
    public static <T> T json2Object(final String json, final Class<T> clazz) throws IOException {
        return (T)JSONUtils2.mapper.readValue(json, (Class)clazz);
    }
    
    public static List<?> json2List(final String json, final TypeReference<?> typeRef) throws IOException {
        final List<?> list = (List<?>)JSONUtils2.mapper.readValue(json, (TypeReference)typeRef);
        return list;
    }
    
    static {
        (mapper = new ObjectMapper()).configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
        JSONUtils2.mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
        JSONUtils2.mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
        JSONUtils2.mapper.configure(JsonParser.Feature.ALLOW_MISSING_VALUES, true);
        JSONUtils2.mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
    }
}
